package com.mg.jsfapp.bean.listener;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

@ManagedBean
public class ActionListenerBean {
	public void handleActionMethod(ActionEvent event) {
		FacesContext.getCurrentInstance().addMessage(
				null,
				new FacesMessage("a4j:actionListener listener invoked at "
						+ new Date()));
	}

	public ActionListener getAnotherListener() {
		return new ActionListener() {
			@Override
			public void processAction(ActionEvent arg0)
					throws AbortProcessingException {
				FacesContext.getCurrentInstance().addMessage(
						null,
						new FacesMessage(
								"a4j:actionListener binding invoked at "
										+ new Date()));
			}
		};
	}

	public static class ActionListenerImpl implements ActionListener {
		@Override
		public void processAction(ActionEvent arg0)
				throws AbortProcessingException {
			FacesContext.getCurrentInstance().addMessage(
					null,
					new FacesMessage("a4j:actionListener type invoked at "
							+ new Date()));
		}
	}
}
